# !/usr/bin/env python
# -*- coding:utf-8 -*-
# project name: bitu-Interface-test
# author: "Lei Yong" 
# creation time: 2019/7/31 15:24
# Email: leiyong711@163.com

import os
import xlrd
from datetime import datetime
from xlrd import xldate_as_tuple
import pandas as pd


def get_excel_data(file_name):
    df = pd.read_csv(file_name, sep=',', header=0)

    # 将Nan转为None
    df = df.where(df.notnull(), None)

    # 获取csv首行作为字典键名
    head = df.columns

    # 存放用例数据
    data = []

    # 表格数据处理
    for index, row in df.iterrows():

        # 把每行测试用例转json
        temp = {k: v for k, v in zip(head, row.values)}
        temp["fileName"] = os.path.basename(file_name)
        data.append(temp)

    return data



if __name__ == "__main__":
    # print(get_excel_data("../case/Phone.xlsx"))
    print(get_excel_data("../case/Phone.csv"))
